package com.breadenglish.cms.api.app.sys.manager;

import com.breadenglish.cms.api.app.domain.model.ComboboxData;
import com.breadenglish.cms.api.app.sys.service.ComboboxService;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 字典下拉
 * User: guoyao
 * Date: 13-12-23
 * Time: 下午2:21
 */
@Controller
@RequestMapping("/sys")
public class ComboboxController {


    private final static Logger logger = LoggerFactory.getLogger(ComboboxController.class);

    @Resource
    private ComboboxService comboboxService;

    /**
     * 根据字典类型查询符合条件的字典列表
     *
     * @param type     字典类型
     * @param selected 默认选择项
     * @return 字典列表
     */
    @RequestMapping(value = "/queryComboboxByDict.html")
    @ResponseBody
    public List<ComboboxData> queryComboboxByDict(@RequestParam(value = "type", required = false) String type,
                                                  @RequestParam(value = "selected", required = false) String selected) throws Throwable {
        return comboboxService.queryDictByClass(type, selected);
    }


    /**
     * 根据地区查询符合条件的省列表
     *
     * @param districtId 地区id
     * @param selected   默认选中
     * @return 省列表
     */
    @RequestMapping(value = "/queryComboboxByProvince.html")
    @ResponseBody
    public List<ComboboxData> queryComboboxByProvince(@ModelAttribute("districtId") String districtId, @ModelAttribute("selected") String selected) throws Throwable {
        return comboboxService.queryProvince(districtId, selected);
    }

    /**
     * 根据省查询符合条件的城市列表
     *
     * @param provinceId 省id
     * @param selected   默认选中
     * @return 城市列表
     */
    @RequestMapping(value = "/queryComboboxByCity.html")
    @ResponseBody
    public List<ComboboxData> queryComboboxByCity(@ModelAttribute("provinceId") String provinceId, @ModelAttribute("selected") String selected) throws Throwable {
        return comboboxService.queryCity(provinceId, selected);
    }

    /**
     * 根据城市查询符合条件的区域列表
     *
     * @param cityId   城市id
     * @param selected 默认选中
     * @return 区域列表
     */
    @RequestMapping(value = "/queryComboboxByArea.html")
    @ResponseBody
    public List<ComboboxData> queryComboboxByArea(@ModelAttribute("cityId") String cityId, @ModelAttribute("selected") String selected) throws Throwable {
        return comboboxService.queryArea(cityId, selected);
    }


}
